import pandas as pd

# 风向
WIND_DIRECTION = {
    "北风": 1,
    "东北风": 2,
    "东风": 3,
    "东南风": 4,
    "南风": 5,
    "西风": 6,
    "西南风": 7,
    "西北风": 8,
    "无固定风向": 9,
}
# 风速
WIND_SPEED = {
    "<3级": 2,
    "3-4级": 3.5,
    "4-5级": 4.5,
    "5-6级": 5.5,
    "6-7级": 6.5,
    "7-8级": 7.5,
    "8-9级": 8.5,
}
# 天气类型
WEATHER = {
    "雾": 1,
    "大雨": 2,
    "中雨": 3,
    "小雨": 4,
    "阴": 5,
    "多云": 6,
    "晴": 7,
    "雷阵雨": 8,
    "阵雨": 9,
    "小到中雨": 10,
    "大到暴雨": 11,
    "暴雨": 12,
    "雨夹雪": 13,
    "雪": 14,
    "中雪": 15,
    "暴雪": 16,
    "沙尘": 17,
    "冰雹": 18,
    "多云转晴": 19,
    "晴转多云": 20,
    "小雨转阴": 21,
    "多云转阴": 22,
    "阴转多云": 23,
    "霾": 25,
    "冻雨": 26,
}

def df_clean(df: pd.DataFrame):
    # 删除数据空列
    s1 = set(df.columns)
    df = df.dropna(axis=1, how="all")
    s2 = set(df.columns)
    s = s1 - (s1 & s2)
    if len(s) > 0:
        print(f"删除缺失数据列{s}")
    
    # 向后填充空值，最大数量为8，若仍存在空值则置为0
    for col in df.columns:
        df.loc[:, col] = df[col].fillna(method="ffill", limit=8)
        # TODO:针对不同的列，采用不同方法
        df.loc[:, col] = df[col].fillna(value=0)
    print("缺失数据已补齐！")
    return df